<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <!--公用头部-->
    <th:block th:replace="common/head::commonHead('修改密码-小邑')"/>
    <style>
        #formAdvForm .layui-row {
            margin-top: 20px;
        }

        #formAdvForm .layui-form-item {
            margin-bottom: 0;
        }

        #formAdvForm .layui-form-item .layui-inline {
            margin-bottom: 25px;
            margin-right: 0;
        }

        #headImg {
            position: relative;
            border: 1px dashed #e2e2e2;
            background-color: #fff;
            text-align: center;
            cursor: pointer;
            color: #999;
            width: 100px !important;
            height: 100px !important;
            border-radius: 50%
        }

        #headImg .layui-icon {
            font-size: 50px;
            color: #009688
        }
    </style>
</head>
<!--公用js-->
<th:block th:replace="common/head::commonJs"/>
<th:block th:replace="common/head::loginJs" />
<script>
    $(function () {
        $("#formAdvForm .layui-row").css("marginLeft","45%");
    })
</script>
<body marginwidth="0" marginheight="0">
<form class="layui-form" action="" id="formAdvForm" lay-filter="formAdvForm">
    <div class="layui-fluid  layui-fluid-btn">
        <div class="layui-col-md12">
            <div class="layui-card" style="margin: 10px;">
                <div class="layui-card-body">
                    <div class="layui-form-item">
                        <div class="layui-inline layui-col-md12">
                            <label class="layui-form-label layui-form-required">原始密码</label>
                            <div class="layui-input-block">
                                <input type="password" name="oldPassword" id="oldPassword" lay-verify="psw"
                                       placeholder="请输入密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline layui-col-md12">
                            <label class="layui-form-label layui-form-required">密码</label>
                            <div class="layui-input-block">
                                <input type="password" name="password" id="password" lay-verify="psw"
                                       placeholder="请输入密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline layui-col-md12">
                            <label class="layui-form-label layui-form-required">确认密码</label>
                            <div class="layui-input-block">
                                <input type="password" lay-verify="equalTo" lay-equalTo="#password" placeholder="请确认密码"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="form-group-bottom">
                        <button id="subBtn" class="xy-btn xy-btn-primary subCheckBtn" lay-submit lay-filter="formBtn">提交</button>
                        <button type="reset" class="xy-btn ">重置</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>

    layui.use(['layer', 'jquery', 'form', 'formX',  'notice',  'miniAdmin'], function () {
        var $ = layui.jquery
            , form = layui.form
            , miniAdmin = layui.miniAdmin
            , formX = layui.formX
            , notice = layui.notice
            , layer = layui.layer;
        //监听提交
        form.on('submit(formBtn)', function (data) {
            var formData = data.field;
            formData.account=user.account;
            if (formData.oldPassword == formData.password){
                top.layui.notice.msg("原始密码不能与新密码一致~" ,{icon: 2,position:"topCenter"});
                return false;
            }
            var loadIndex = null;
            checkSubBtn(1);
            sendAjaxPostToCallback(
                basePath+"/user/updatePassword",
                formData,
                function (result){
                    if (result.success){
                        top.layui.notice.msg(result.msg ,{icon: 1,position:"topCenter"});
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        miniAdmin.loginOut();
                    }else{
                        checkSubBtn(2);
                        top.layui.notice.msg(result.msg ,{icon: 2,position:"topCenter"});
                    }
                },
                function (data) {
                    checkSubBtn(2);
                    if (utils.string.isEmpty(data) && utils.string.isEmpty(data.msg)){
                        top.layui.notice.msg(data.msg ,{icon: 2,position:"topCenter"});
                    }else{
                        top.layui.notice.msg("服务器内部错误，请联系管理员~", {icon: 2,position:"topCenter"});
                    }
                },
                function (){
                    loadIndex = layer.load(1);
                },
                function (){
                    layer.close(loadIndex);
                },
            )
            return false;
        });
    });
</script>
</body>
</html>
